/*
 SGRecyclableItem.m
 Date Created: March 6, 2010
 
 Authors: Karanvir Gill <viper1029@gmail.com>
          Frank Lau <flaua@sfu.ca>
 
 Copyright (C) 2010 Green-Power
 
 URL: http://code.google.com/p/green-power
 
 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 3 of the License, or
 (at your option) any later version.
 
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 
 $Id$
 */

#import "SGRecyclableItem.h"


@implementation SGRecyclableItem
@synthesize isBeingDragged;
@synthesize hasBeenDropped;
@synthesize depositValue;
@synthesize uniqueName;

- (SGRecyclableItem*)initWithType:(SGRecyclableType*)itemType xLocation:(float)xCoor yLocation:(float)yCoor{
	self = [super init];
	if( self ) {
		//create temporary image to determine the size of the frame to create
		UIImage *tempImage = [UIImage imageNamed:itemType.image];
		[self initWithFrame:CGRectMake(xCoor, yCoor, tempImage.size.width, tempImage.size.height)];
		[self setImage:tempImage];
		self.center = CGPointMake(xCoor,yCoor);
		//[tempImage release];
		
		uniqueName = [itemType uniqueName];
		depositValue = [itemType depositValue];
		isBeingDragged = false;
		hasBeenDropped = false;
	}
	return self;
}

- (void) touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event {
  // Perform the move
	CGPoint currentLocation = [[touches anyObject] locationInView:self];
	CGRect frame = [self frame];
	
	frame.origin.x += currentLocation.x - startLocation.x;
	frame.origin.y += currentLocation.y - startLocation.y;
	[self setFrame:frame];
}

- (void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
	isBeingDragged = true;
	CGPoint currentLocation = [[touches anyObject] locationInView:self]; 
	startLocation = currentLocation;
	[[self superview] bringSubviewToFront:self];
}

- (void) touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event {
	isBeingDragged = false;
	hasBeenDropped = true;
}


@end
